/* rqexrt.p   - REQUISITION GET EXCHANGE RATE                                 */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/*V8:ConvertMode=NoConvert                                                    */
/* Revision: 8.6    LAST MODIFIED BY: 05/05/97  By: B. Gates          *J1Q2*  */
/* REVISION: 8.6E   LAST MODIFIED: 07/21/98   BY: *L040* Charles Yne          */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* myb                  */


/*L040*/ {mfdeclre.i}
         define input parameter p_from_curr like rqm_curr no-undo.
         define input parameter p_to_curr like rqm_curr no-undo.
/*L040*/ define input parameter p_ratetype like exr_ratetype no-undo.
         define output parameter p_exchg_rate as decimal no-undo.
/*L040*/ define output parameter p_exchg_rate2 as decimal no-undo.
/*L040*/ define output parameter p_error_number like msg_nbr no-undo.

         define variable exchg_rate1 as decimal no-undo.
         define variable exchg_rate2 as decimal no-undo.
/*L040*/ define variable exchg_rate3 as decimal no-undo.
/*L040*/ define variable exchg_rate4 as decimal no-undo.
/*L040*/ define variable mc-error-number like msg_nbr no-undo.
/*L040*/ define variable p_in_error_number like msg_nbr no-undo.

         if p_from_curr = p_to_curr then do:
            p_exchg_rate = 1.
/*L040*/    p_exchg_rate2 = 1.
            leave.
         end.

         p_exchg_rate = ?.

/*L040*  {gpgtex8.i */
/*L040*  &date=today */
/*L040*  &ent_curr=p_to_curr */
/*L040*  &curr=p_from_curr */
/*L040*  &exch_from=exd_rate */
/*L040*  &exch_to=p_exchg_rate} */
/*L040*/ {gprunp.i "mcpl" "p" "mc-get-ex-rate"
          "(input p_from_curr,
            input p_to_curr,
            input p_ratetype,
            input today,
            output p_exchg_rate,
            output p_exchg_rate2,
            output mc-error-number)"}
/*L040*/ p_error_number = mc-error-number.

/*L040*/ if p_error_number <> 0 then do:
/*L040*/    {gprunp.i "mcpl" "p" "mc-get-ex-rate"
             "(input p_from_curr,
               input base_curr,
               input p_ratetype,
               input today,
               output exchg_rate1,
               output exchg_rate2,
               output p_in_error_number)"}
/*L040*/    if p_in_error_number = 0 then do:
/*L040*/    {gprunp.i "mcpl" "p" "mc-get-ex-rate"
             "(input base_curr,
               input p_to_curr,
               input p_ratetype,
               input today,
               output exchg_rate3,
               output exchg_rate4,
               output p_in_error_number)"}
/*L040*/    end.
/*L040*/    if p_in_error_number = 0 then do:
/*L040*/       {gprunp.i "mcpl" "p" "mc-combine-ex-rates"
          "(input exchg_rate1,
            input exchg_rate2,
            input exchg_rate3,
            input exchg_rate4,
            output p_exchg_rate,
            output p_exchg_rate2)"}
/*L040*/    end.
/*L040*/    else assign p_exchg_rate = 1
            p_exchg_rate2 = 1.
/*L040*/    assign p_error_number = p_in_error_number.
/*L040*/ end.

/*L040*  if p_exchg_rate = ? then do:
*           /*TRY CONVERTING FROM "FROM" CURR TO BASE CURR THEN TO "TO" CURR*/
*           find first gl_ctrl no-lock.
*
*           exchg_rate1 = ?.
*           exchg_rate2 = ?.
*
*           {gpgtex8.i
*           &date=today
*           &ent_curr=gl_base_curr
*           &curr=p_from_curr
*           &exch_from=exd_rate
*           &exch_to=exchg_rate1}
*
*           {gpgtex8.i
*           &date=today
*           &ent_curr=p_to_curr
*           &curr=gl_base_curr
*           &exch_from=exd_rate
*           &exch_to=exchg_rate2}
*
*           p_exchg_rate = exchg_rate1 * exchg_rate2.
*        end.
*L040*/
